#ifndef WEBSOCKETCONNECTION_H_
#define WEBSOCKETCONNECTION_H_

#include <iostream>
#include "ByteString.h"
#include "HighLevelConnection.h"
using namespace std;

class WebSocketConnection: public HighLevelConnection {
public:
	WebSocketConnection(int sockfd, string location);
	virtual ~WebSocketConnection();
	static string makeSHA1Hash(string message);
	int read(char* buffer, int bufferSize, bool& fin);
	int send(const char* buffer, int bufferSize, bool fin);
	void close();

protected:
	virtual void listener();

private:
	int readFrame(char* buffer, int bufferSize, bool& fin);
	int framePayloadPos;
	int framePayloadLength;
	ByteString framePayloadBytes;
	unsigned char frameInfo;
	unsigned char frameMask[4];
	unsigned char state;
	bool cont;
};

const string WS_GUID = "258EAFA5-E914-47DA-95CA-C5AB0DC85B11";
const unsigned char WS_OPEN = 0;
const unsigned char WS_CLOSED = 1;
const unsigned char WS_CLOSING = 2;

//const string WS_VERSIONS = "Sec-WebSocket-Version: 14";

#endif /* WEBSOCKETCONNECTION_H_ */
